package com.rentong.wx.sys.service.impl;

import com.rentong.wx.cust.dto.ServiceProjectDto;

import com.rentong.wx.sys.dao.SysServiceDao;
import com.rentong.wx.sys.service.SysServiceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SysServiceServiceImpl implements SysServiceService {

    @Resource
    private SysServiceDao sysServiceDao;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public List<List<ServiceProjectDto>> serviceProjectList(Long bigTypeId, Long smallTypeId, String serviceName, Long chefId) {
        List<ServiceProjectDto> serviceProjectDto = sysServiceDao.serviceProjectList(bigTypeId, smallTypeId, serviceName, chefId);

        List<List<ServiceProjectDto>> serviceProjectDtoList = new ArrayList<>();
        List<ServiceProjectDto> projectDto = null;
        Long smallTypeId2 = 0L;
        int i = 0;

        for(ServiceProjectDto item: serviceProjectDto){
            i++;
            if (!smallTypeId2.equals(item.getSmallTypeId())){

                if (projectDto != null){
                    serviceProjectDtoList.add(projectDto);
                }

                projectDto = new ArrayList<>();

            }

            projectDto.add(item);
            smallTypeId2=item.getSmallTypeId();
            if (!smallTypeId2.equals(item.getSmallTypeId()) || serviceProjectDto.size() == i) {

                if (projectDto != null) {
                    serviceProjectDtoList.add(projectDto);
                }
            }
        }

        return serviceProjectDtoList;
    }




}